package com.fulu.game.bi.controller.platform;

import com.fulu.game.bi.AssertHelper;
import com.fulu.game.bi.common.exception.BizException;
import com.fulu.game.bi.entity.bo.channel.CashConvertListBO;
import com.fulu.game.bi.entity.bo.channel.CashInvestListBO;
import com.fulu.game.bi.entity.bo.channel.CashRefundListBO;
import com.fulu.game.bi.entity.dto.CashConvertListDTO;
import com.fulu.game.bi.entity.dto.CashInvestListDTO;
import com.fulu.game.bi.entity.dto.CashRefundListDTO;
import com.fulu.game.bi.entity.enums.PlatformCashEnum;
import com.fulu.game.bi.entity.vo.Result;
import com.fulu.game.bi.entity.vo.common.NameMsgVO;
import com.fulu.game.bi.redis.service.cash.PlatformCashService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 平台资金
 */
@RestController
@RequestMapping("/api/platform/cash")
@Slf4j
public class PlatformCashController {

    @Autowired
    private PlatformCashService platformCashService;

    /**
     * 平台资金-实时数据
     */
    @RequestMapping("/real-time")
    public Result realTime(Integer type) {
        AssertHelper.assertNotNull(type, () -> new BizException("类型不能为空"));
        return Result.success().data(platformCashService.realTime(type));
    }

    /**
     * 平台资金-折线图
     *
     * @return
     */
    @RequestMapping("/line-chart")
    public Result<List<NameMsgVO>> stat(Integer type) {
        Map<String, String> cacheMap = new LinkedHashMap<>();
        PlatformCashEnum.CashTypeEnum anEnum = PlatformCashEnum.CashTypeEnum.getByType(type);
        switch (anEnum) {
            case INVEST: {
                cacheMap.put("充值人数", "userNum");
                cacheMap.put("充值次数", "num");
                cacheMap.put("充值金额", "money");
                break;
            }
            case CONVERT: {
                cacheMap.put("兑换人数", "userNum");
                cacheMap.put("兑换次数", "num");
                cacheMap.put("兑换支出金额", "outMoney");
                cacheMap.put("兑换收入金额", "inMoney");
                break;
            }
            case REFUND: {
                cacheMap.put("退款人数", "userNum");
                cacheMap.put("退款次数", "num");
                cacheMap.put("退款金额", "money");
                break;
            }
            default:
                break;
        }
        List<NameMsgVO> list = cacheMap.entrySet().stream()
                .map(entry -> {
                    NameMsgVO idNameVO = new NameMsgVO();
                    idNameVO.setName(entry.getValue());
                    idNameVO.setMsg(entry.getKey());
                    return idNameVO;
                })
                .collect(Collectors.toList());
        return Result.success().data(list).msg("获取成功");
    }


    /**
     * 平台资金-充值列表
     */
    @RequestMapping("/invest-list")
    public Result investList(CashInvestListDTO investListDTO) {
        CashInvestListBO cashInvestListBO = new CashInvestListBO();
        BeanUtils.copyProperties(investListDTO, cashInvestListBO);
        return Result.success().data(platformCashService.investList(cashInvestListBO));
    }

    /**
     * 平台资金-充值导出
     */
    @RequestMapping("/invest-export")
    public void investExport(CashInvestListDTO investListDTO) {
        CashInvestListBO cashInvestListBO = new CashInvestListBO();
        BeanUtils.copyProperties(investListDTO, cashInvestListBO);
        platformCashService.investExport(cashInvestListBO);
    }

    /**
     * 平台资金-兑换列表
     *
     * @return
     */
    @RequestMapping("/convert-list")
    public Result convertList(CashConvertListDTO cashConvertListDTO) {
        CashConvertListBO cashConvertListBO = new CashConvertListBO();
        BeanUtils.copyProperties(cashConvertListDTO, cashConvertListBO);
        return Result.success().data(platformCashService.convertList(cashConvertListBO)).msg("获取成功");
    }


    /**
     * 平台资金-兑换导出
     *
     * @return
     */
    @RequestMapping("/convert-export")
    public void convertExport(CashConvertListDTO cashConvertListDTO) {
        CashConvertListBO cashConvertListBO = new CashConvertListBO();
        BeanUtils.copyProperties(cashConvertListDTO, cashConvertListBO);
        platformCashService.convertExport(cashConvertListBO);
    }

    /**
     * 平台资金-退款列表
     *
     * @return
     */
    @RequestMapping("/refund-list")
    public Result refundList(CashRefundListDTO cashRefundListDTO) {
        CashRefundListBO cashRefundListBO = new CashRefundListBO();
        BeanUtils.copyProperties(cashRefundListDTO, cashRefundListBO);
        return Result.success().data(platformCashService.refundList(cashRefundListBO)).msg("获取成功");
    }


    /**
     * 平台资金-退款导出
     *
     * @return
     */
    @RequestMapping("/refund-export")
    public void refundExport(CashRefundListDTO cashRefundListDTO) {
        CashRefundListBO cashRefundListBO = new CashRefundListBO();
        BeanUtils.copyProperties(cashRefundListDTO, cashRefundListBO);
        platformCashService.refundExport(cashRefundListBO);
    }

}
